package com.sushe.servlet;



import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @author Liu
 * @date 2022/4/4
 * @apiNote 插入单条数据
 */
@WebServlet("/insertStudentServlet")
public class insertStudentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("html/text;charset=utf-8");
        String studentNum = request.getParameter("studentNum");
        String studentName = request.getParameter("studentName");
        String studentPhone = request.getParameter("studentPhone");
        String studentIsin = request.getParameter("studentIsin");
        String studentSex = request.getParameter("studentSex");
        String studentBuild = request.getParameter("studentBuild");
        String studentInfo = request.getParameter("studentInfo");
        //Student student = new Student(0, studentNum, studentName, Integer.valueOf(studentSex), Integer.valueOf(studentIsin), studentInfo, Integer.valueOf(studentBuild), studentPhone);
        //try {
        //    StudentDao.insertStudent(student);
        //} catch (SQLException e) {
        //    e.printStackTrace();
        //}
        //重定向
        request.getRequestDispatcher("/allStudentServlet").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
